#include <iostream>
#include <chrono>
#include<opencv2/opencv.hpp>
#include "superpoint.h"

using namespace std;
using namespace cv;

std::vector<float> ApplyTransform(const cv::Mat image){
    cv::Mat resized, floatImage;
	image.convertTo(floatImage, CV_32FC1);

	vector<float> imgData;
	for (int h = 0; h < image.rows; h++)
	{
		for (int w = 0; w < image.cols; w++)
		{
			imgData.push_back(floatImage.at<float>(h, w) / 255.0f);
		}
	}
	return imgData;
}

int main(){
    std::cout<<"Todo..."<<std::endl;
    const std::string img_path = "/ws/zwl/Data/YYGYM/0819-dengdai/1L-F1-G4/euroc/cam0/data/80770886515712.jpg";
    const std::string onnx_path = "/zwj/pro/zwl/Feature/LightGlue-ONNX/weights/superpoint.onnx";
    
	auto sp = SuperPoint(onnx_path, 1);
    cv::Mat img = cv::imread(img_path);
	cv::Mat resize_img;
	cv::resize(img, resize_img, cv::Size(960, 480));
    std::vector<cv::KeyPoint> keypoints;
	cv::Mat descriptors;

	const int iterations = 300;
	sp.DetectAndCompute(resize_img, keypoints, descriptors);
    // 获取当前时间点作为开始时间
    auto start_time = std::chrono::high_resolution_clock::now();
	// 循环执行代码 iterations 万次
    for (int i = 0; i < iterations; ++i) {
		sp.DetectAndCompute(resize_img, keypoints, descriptors);
		std::cout<<keypoints.size()<<std::endl;
	}
	auto end_time = std::chrono::high_resolution_clock::now();
	// 计算总执行时间
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
    std::cout << "infer " << iterations << " iterations: " << duration.count()/(1000*iterations) << " millisecond" << std::endl;

}